package com.dxw.kit.email;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class MailMessage {

	/**
	 * 发件人邮箱
	 */
	private String from;

	/**
	 * 发件人昵称
	 */
	private String nickName;

	/**
	 * 收件人列表
	 */
	private List<String> toList;

	/**
	 * 抄送列表
	 */
	private List<String> ccList;

	/**
	 * 密件抄送列表
	 */
	private List<String> bccList;

	/**
	 * 附件列表
	 */
	private List<File> attachs;

	/**
	 * 邮件内容
	 */
	private String content;

	/**
	 * 邮件主题
	 */
	private String subject;

	/**
	 * 邮件时间
	 */
	private Date date;

	/**
	 * 构造器
	 */
	public MailMessage() {
		this.toList = new ArrayList<String>();
		this.ccList = new ArrayList<String>();
		this.bccList = new ArrayList<String>();
		this.attachs = new ArrayList<File>();
		this.date = new Date();
	}

	// 添加收件人

	public MailMessage addTo(String to) {
		this.toList.add(to);
		return this;
	}

	public MailMessage addTo(String... to) {
		this.toList.addAll(Arrays.asList(to));
		return this;
	}

	public MailMessage addTo(List<String> toList) {
		this.toList.addAll(toList);
		return this;
	}

	// 添加抄送

	public MailMessage addCc(String cc) {
		this.ccList.add(cc);
		return this;
	}

	public MailMessage addCc(String... cc) {
		this.ccList.addAll(Arrays.asList(cc));
		return this;
	}

	public MailMessage addCc(List<String> ccList) {
		this.ccList.addAll(ccList);
		return this;
	}

	// 添加密件抄送

	public MailMessage addBcc(String bcc) {
		this.bccList.add(bcc);
		return this;
	}

	public MailMessage addBcc(String... bcc) {
		this.bccList.addAll(Arrays.asList(bcc));
		return this;
	}

	public MailMessage addBcc(List<String> bccList) {
		this.bccList.addAll(bccList);
		return this;
	}

	// 添加附件

	public MailMessage addFile(File file) {
		if (null == file || !file.exists()) {
			throw new MailException("The File Not Exists!");
		}
		this.attachs.add(file);
		return this;
	}

	public MailMessage addFile(String filePath) {
		File file = new File(filePath);
		addFile(file);
		return this;
	}

	public MailMessage addFile(String... filePaths) {
		for (String filepath : filePaths) {
			addFile(filepath);
		}
		return this;
	}

	public MailMessage addFile(File... files) {
		for (File file : files) {
			addFile(file);
		}
		return this;
	}

	// Get() and Set() 方法

	/**
	 * @return the from
	 */
	public String getFrom() {
		return from;
	}

	/**
	 * @param from
	 *            the from to set
	 */
	public void setFrom(String from) {
		this.from = from;
	}

	/**
	 * @return the nickName
	 */
	public String getNickName() {
		return nickName;
	}

	/**
	 * @param nickName
	 *            the nickName to set
	 */
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	/**
	 * @return the toList
	 */
	public List<String> getToList() {
		return toList;
	}

	/**
	 * @param toList
	 *            the toList to set
	 */
	public void setToList(List<String> toList) {
		this.toList = toList;
	}

	/**
	 * @return the ccList
	 */
	public List<String> getCcList() {
		return ccList;
	}

	/**
	 * @param ccList
	 *            the ccList to set
	 */
	public void setCcList(List<String> ccList) {
		this.ccList = ccList;
	}

	/**
	 * @return the bccList
	 */
	public List<String> getBccList() {
		return bccList;
	}

	/**
	 * @param bccList
	 *            the bccList to set
	 */
	public void setBccList(List<String> bccList) {
		this.bccList = bccList;
	}

	/**
	 * @return the attachs
	 */
	public List<File> getAttachs() {
		return attachs;
	}

	/**
	 * @param attachs
	 *            the attachs to set
	 */
	public void setAttachs(List<File> attachs) {
		this.attachs = attachs;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @param content
	 *            the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * @return the subject
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * @param subject
	 *            the subject to set
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}

	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * @param date
	 *            the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

}
